<template>
    <div class="productVue">
        <div style="width: 100%; height: 40px; display: flex; justify-content: space-between;">
            <input type="text" placeholder="搜索商品" v-model="keywords" style="flex: 1; height: 40px; border-radius: 5px; border: 1px solid #DCDFE6; padding-left: 10px; font-size: 14px;">
            <div style="width: 70px; height: 40px; border-radius: 5px; background: #2561EF; margin-left: 15px; color: #fff; text-align: center; line-height: 40px; cursor: pointer;" @click="searchFun()">搜索</div>
        </div>
        <div class="product" v-for="(item, index) in list" :key="index">
            <img :src="item.image" style="width: 60px; height: 60px; margin-right: 20px;">
            <div class="right">
                <div class="flex-between">
                    <div class="name">{{ item.name }}</div>
                </div>
                <div class="flex-between">
                    <div style="color: #4D4D4D; font-size: 14px;">¥{{ item.price }}</div>
                    <div class="opraVue">
                        <span @click="toDetail(item.id)">商品详情</span>
                        <div class="line"></div>
                        <span @click="sendProduct(item.id)">发送</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import { productLstApi } from '@/api/product';
    export default{
        data(){
            return {
                list: [],
                totalPage: 0,
                page: 1,
                limit: 20,
                keywords: ""
            }
        },
        watch: {
            keywords(){
                if(!this.keywords) this.searchFun()
            }
        },
        methods: {
            sendProduct(id){
                this.$emit("sendProduct", id)
            },
            searchFun(){
                this.list = []
                this.page = 1
                this.getList()
            },
            getList() {
                const param = {
                    page: this.page,
                    limit: this.limit,
                    type: '1',
                    keywords: this.keywords
                }
                productLstApi(param).then((res) => {
                    this.list = this.list.concat(res.list)
                    this.totalPage = res.totalPage;
                }).catch((err) => {
                    console.log(err)
                });
            },
            getMore(){
                if(this.page>=this.totalPage) return
                this.page ++
                this.getList()
            },
            toDetail(id){
                this.$emit("toDetail", "product", id)
            }
        }
    }
</script>


<style lang="scss" scoped>
    input::-webkit-input-placeholder { font-size: 13px; color: #999; }  //使用webkit内核的浏览器
    input:-moz-placeholder{ font-size: 13px;  color: 999; }   //Firefox版本4-18
    input::-moz-placeholder{ font-size: 13px;color: 999;  }  //Firefox版本19+
    input:-ms-input-placeholder { font-size: 13px; color: 999; } ////IE浏览器
    .productVue {
        width: 100%;
        padding: 20px;
        .product {
            width: 100%;
            display: flex;
            padding-bottom: 15px;
            border-bottom: 1px solid #f5f5f5;
            margin-top: 15px;
            .right {
                flex: 1;
                height: 60px;
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                .flex-between {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    .name {
                        color: #4D4D4D;
                    }
                    .btn {
                        width: 60px;
                        height: 30px;
                        background: #2561EF;
                        border-radius: 5px;
                        line-height: 30px;
                        text-align: center;
                        color: #fff;
                        cursor: pointer;
                    }
                    .opraVue {
                        margin-top: 15px;
                        display: flex;
                        justify-content: flex-end;
                        span {
                            color: #2561EF;
                            font-size: 15px;
                            cursor: pointer;
                        }
                        .line {
                            width: 1px;
                            height: 16px;
                            background: #2561EF;
                            margin: 0 15px;
                        }
                        span:hover {
                            opacity: 0.7;
                        }
                    }
                }
            }
        }
    }
</style>